package cn.softTank.graph
{
	import cn.softTank.component.BasicActivity;
	
	import mx.core.UIComponent;
	
	public class Arrow extends UIComponent
	{
		
		public var thickness:Number;
		public var color:uint;
		private var start:BasicActivity;
		private var end:BasicActivity;
		
		public function Arrow(start:BasicActivity, end:BasicActivity)
		{
			this.start=start;
			this.end=end;
		}
		public function drawArrow(thickness:Number, color:uint, start:BasicActivity=null, end:BasicActivity=null):void
		{
			this.thickness=thickness;
			this.color=color;
			if(start!=null)
				this.start=start;
			if(end!=null)
				this.end=end;
			draw();
		}
		public function repaint(start:BasicActivity=null, end:BasicActivity=null):void
		{
			if(start!=null)
				this.start=start;
			if(end!=null)
				this.end=end;
			this.graphics.clear();
			draw();
		}
		private function draw():void
		{
			// Get location of BasicActivity.
			var startX:Number=start.x+start.parent.x+start.parent.parent.x+start.parent.parent.parent.x+start.width/2;
			var startY:Number=start.y+start.parent.y+start.parent.parent.y+start.parent.parent.parent.y+start.height/2;
			var endX:Number=end.x+end.parent.x+end.parent.parent.x+end.parent.parent.parent.x+end.width/2;
			var endY:Number=end.y+end.parent.y+end.parent.parent.y+end.parent.parent.parent.y+end.height/2;
			this.graphics.lineStyle(thickness, color);
			this.graphics.moveTo(startX, startY);
			this.graphics.lineTo(endX, endY);
			trace("("+start.x+","+start.y+") to ("+end.x+","+end.y+")");
			trace("this arrow is from: ("+startX+","+startY+") to ("+endX+","+endY+")");
		}

	}
}